# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=wcc
pkgver=v0.0.11.r41.gfad40be
pkgrel=1
epoch=1
pkgdesc='The Witchcraft Compiler Collection.'
groups=('blackarch' 'blackarch-binary' 'blackarch-misc')
arch=('x86_64' 'aarch64')
url='https://github.com/endrazine/wcc'
license=('MIT' 'BSD' 'custom:unknown')
depends=('capstone' 'libelf' 'zlib' 'gsl')
makedepends=('git' 'clang' 'cargo')
source=("git+https://github.com/endrazine/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  rm -rf wcc

  git clone --recursive $url
}

build() {
  cd $pkgname

  make
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"

  make DESTDIR="$pkgdir" install

  install -Dm 644 -t "$pkgdir/usr/share/man/man1/" doc/manpages/*.1
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md
  cp -a doc/* "$pkgdir/usr/share/doc/$pkgname/"
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

